package api

import (
	"github.com/astaxie/beego/validation"
	"github.com/gin-gonic/gin"
	"net/http"
	"soudian_oversea_api/pkg/app"
	"soudian_oversea_api/pkg/e"
)

type register struct {
	Username string `valid:"Required; MaxSize(2)"`
	Password string `valid:"Required; MaxSize(50)"`
}

func PostRegister(c *gin.Context) {
	valid := validation.Validation{}
	appG := app.Gin{C: c}
	username := c.PostForm("username")
	password := c.PostForm("password")

	r := register{Username: username, Password: password}

	ok, _ := valid.Valid(&r)

	if !ok {
		app.MarkErrors(valid.Errors)
		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
		return
	}

	appG.Response(http.StatusOK, e.SUCCESS, map[string]interface{}{
		"created": true,
	})
}
